﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;

namespace LineTools
{
    public class LineJig : EntityJig
    {
        #region
        private Point3d jStartPoint;  //直线的起点
        private Point3d jEndPoint;  //直线的终点
        private string jPromptStr;  //提示信息
        private string[] jKeyword;  //交互关键字
        #endregion

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="startPoint">起点</param>
        /// <param name="promptStr">终点</param>
        /// <param name="keywords">交互关键字</param>
        public LineJig(Point3d startPoint, string promptStr, string[] keywords)
            : base(new Line())
        {
            jStartPoint = startPoint;
            ((Line)Entity).StartPoint = jStartPoint;
            jPromptStr = promptStr;

            jKeyword = keywords;
        }
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            //声明提示信息类
            JigPromptPointOptions jppo = new JigPromptPointOptions(jPromptStr);
            //添加关键字
            for (int i = 0; i < jKeyword.Length; i++)
            {
                jppo.Keywords.Add(jKeyword[i]);
            }
            char space = (char)32;
            jppo.Keywords.Add(space.ToString());
            //设置获取的信息类型 
            jppo.UserInputControls = UserInputControls.Accept3dCoordinates;
            //jppo.Cursor = CursorType.RubberBand;  //虚线
            //取消系统自动添加的关键字提示信息
            jppo.AppendKeywordsToMessage = false;
            PromptPointResult ppr = prompts.AcquirePoint(jppo);
            jEndPoint = ppr.Value;
            return SamplerStatus.NoChange;
        }
        protected override bool Update()
        {
            ((Line)Entity).EndPoint = jEndPoint;  //更新终点
            return true;
        }
        /// <summary>
        /// 返回图形对象
        /// </summary>
        /// <returns>Entity</returns>
        public Entity GetEntity()
        {
            return Entity;
        }
    }
}